export function getIdByPath(menus: any[], path: string): any {
  for (const menu of menus) {
    if (menu.type != 1 && menu.url === path) {
      return menu.id
    } else {
      const menuId = getIdByPath(menu.children ?? [], path)
      if (menuId) {
        return menuId
      }
    }
  }
}

// 根据菜单获取用户权限
export function mapMenuWithPermission(useMenu: any[]) {
  const primissions: any[] = []

  const _getMenuPerimissions = (useMenu: any[]) => {
    useMenu.forEach((menu) => {
      if (menu.type !== 3) {
        _getMenuPerimissions(menu.children ?? [])
      } else {
        primissions.push(menu.permission)
      }
    })
  }
  _getMenuPerimissions(useMenu)
  return primissions
}

// 除了一级菜单,递归获取子项id
export function getSubMenuId(menuList: any) {
  const list: any = []
  const _getId = (menu: any) => {
    if (menu.type == 1) {
      _getId(menu.children)
    } else {
      if (menu instanceof Array) {
        menu.forEach((item) => {
          _getId(item)
        })
      } else {
        list.push(menu.id)
        _getId(menu.children ?? [])
      }
    }
  }
  _getId(menuList)
  return list
}
